﻿/// <reference path="../classes.js" />
/// <reference path="qunit-1.11.0.js" />

// Methods for testing:
//  - initialize
//  - renderPartial
//  - renderFull

(function () {
    module("Initialization");
    test("Testing with only machine constructor", function () {
        var years = 7,
            guarantee = 5,
            amortizationPeriod = 10;

        var server = new Server(years, guarantee, amortizationPeriod);
        equal(server.yearsOld, years, "yearsOld");
        equal(server.guarantee, guarantee, "guarantee");
        equal(server.amortizationPeriod, amortizationPeriod, "amortizationPeriod");
    });
    test("Testing with all parameters", function () {
        // function ($super, years, guarantee, amortizationPeriod, mileage, OS, usage)
        var years = 7,
            guarantee = 5,
            amortizationPeriod = 10,
            mileage = 5,
            operationalSystem = "ubuntu",
            usage = 7;

        var server = new Server(years, guarantee, amortizationPeriod, mileage, operationalSystem, usage);
        equal(server.yearsOld, years, "yearsOld");
        equal(server.guarantee, guarantee, "guarantee");
        equal(server.amortizationPeriod, amortizationPeriod, "amortizationPeriod");
        equal(server.cores, mileage, "mileage");
        equal(server.os, undefined, "OS - undefiend");
        equal(server.usage, usage, "usage");
    });
    test("Initialization with 4 parameters", function () {
        // function ($super, years, guarantee, amortizationPeriod, mileage, OS, usage)
        var years = 7,
            guarantee = 5,
            amortizationPeriod = 10,
            mileage = 5;

        var server = new Server(years, guarantee, amortizationPeriod, mileage);
        equal(server.yearsOld, years, "yearsOld");
        equal(server.guarantee, guarantee, "guarantee");
        equal(server.amortizationPeriod, amortizationPeriod, "amortizationPeriod");
        equal(server.cores, mileage, "mileage");
    });

    module("RenderPartial");
    test("Render server", function () {
        var years = 7,
            guarantee = 5, 
            amortizationPeriod = 10,
            mileage = 5;

        var server = new Server(years, guarantee, amortizationPeriod, mileage);
        var fixture = document.getElementById("qunit-fixture");
        var container = server.renderPartial()[0];
        $(fixture).append(container);
        equal(container.className, "server");
    });

    module("RenderFull");
    test("Render server", function () {
        var years = 7,
            guarantee = 5,
            amortizationPeriod = 10,
            mileage = 5;

        var server = new Server(years, guarantee, amortizationPeriod, mileage);
        var fixture = document.getElementById("qunit-fixture");
        var container = server.renderFull();
        $(fixture).append(container);

        var divs = fixture.getElementsByTagName("div");
        equal(divs.length, 8);
    });
}());